package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.it.networkAssets;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.networkassets.InterfaceStatus;
import com.glsc.ngateway.common.api.platform.dto.it.networkassets.InterfaceStatusDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface InterfaceStatusRepo extends JpaRepository<InterfaceStatus, Long> {


    /**
     * 分页
     */
    @Query(value = "select * from t_gw_it_net_assets_interface_status t " +
            "where deleted = 0 " +
            "and if( :#{#interfaceStatusDto.host} is not null, t.host like CONCAT('%', :#{#interfaceStatusDto.host}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifIndex} is not null, t.if_index like CONCAT('%', :#{#interfaceStatusDto.ifIndex}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifName} is not null, t.if_name like CONCAT('%', :#{#interfaceStatusDto.ifName}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifType} is not null, t.if_type like CONCAT('%', :#{#interfaceStatusDto.ifType}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifHighSpeed} is not null, t.if_high_speed like CONCAT('%', :#{#interfaceStatusDto.ifHighSpeed}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifOperStatus} is not null, t.if_oper_status like CONCAT('%', :#{#interfaceStatusDto.ifOperStatus}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifErrDis} is not null, t.if_err_dis like CONCAT('%', :#{#interfaceStatusDto.ifErrDis}, '%'), 1=1 ) " +
//            "order by if( :sortsSQL is not null , :sortsSQL, t.update_time desc) " +
            "", nativeQuery = true)
    Page<InterfaceStatus> page(Pageable pageable, @Param("interfaceStatusDto") InterfaceStatusDto interfaceStatusDto);

    @Query(value = "select * from t_gw_it_net_assets_interface_status t " +
            "where deleted = 0 " +
            "and if( :#{#interfaceStatusDto.host} is not null, t.host like CONCAT('%', :#{#interfaceStatusDto.host}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifIndex} is not null, t.if_index like CONCAT('%', :#{#interfaceStatusDto.ifIndex}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifName} is not null, t.if_name like CONCAT('%', :#{#interfaceStatusDto.ifName}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifType} is not null, t.if_type like CONCAT('%', :#{#interfaceStatusDto.ifType}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifHighSpeed} is not null, t.if_high_speed like CONCAT('%', :#{#interfaceStatusDto.ifHighSpeed}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifOperStatus} is not null, t.if_oper_status like CONCAT('%', :#{#interfaceStatusDto.ifOperStatus}, '%'), 1=1 ) " +
            "and if( :#{#interfaceStatusDto.ifErrDis} is not null, t.if_err_dis like CONCAT('%', :#{#interfaceStatusDto.ifErrDis}, '%'), 1=1 ) " +
            "", nativeQuery = true)
    List<InterfaceStatus> queryAll(@Param("interfaceStatusDto") InterfaceStatusDto param);
}
